import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { BaseService } from '@/common/base/base.service'

import { QuestionRecord } from './entities/question-record.entity'
import { Question } from './entities/question.entity'

@Injectable()
export class QuestionService extends BaseService<Question, 'questionId'> {
  constructor(
    @InjectRepository(Question)
    private repo: Repository<Question>,
  ) {
    super(repo)
  }

  closeOtherEnabled() {
    return this.repo.update(
      {
        isEnabled: true,
      },
      { isEnabled: false },
    )
  }
}

@Injectable()
export class QuestionRecordService extends BaseService<QuestionRecord, 'questionRecordId'> {
  constructor(
    @InjectRepository(QuestionRecord)
    private repo: Repository<QuestionRecord>,
  ) {
    super(repo)
  }

  save(data: Omit<QuestionRecord, 'questionRecordId' | 'question'>) {
    return this.repo.save(data)
  }
}
